package com.mmd.manage.web;

import com.alibaba.fastjson.JSONArray;
import com.mmd.bean.CODE;
import com.mmd.bean.WebJsonBean;
import com.mmd.exception.GameException;
import com.mmd.manage.service.ModeMYCService;
import com.mmd.manage.vo.ModeMYCVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 燃油费
 */
@RequestMapping(value = "/api/myc")
@Controller
public class ModeMYCController {

    @Autowired
    private ModeMYCService modeMYCService;

    /**
     * 获取燃油费设置
     *
     * @return
     */
    @RequestMapping(value = "/getMYCList")
    @ResponseBody
    public WebJsonBean getMYCList() {
        return new WebJsonBean(CODE.SUCCESS, modeMYCService.getModeMYCList());
    }

    /**
     * 设置燃油费
     *
     * @return
     */
    @RequestMapping(value = "/setMYC")
    @ResponseBody
    public WebJsonBean setMYC(String mycStr) {
        if (StringUtils.isEmpty(mycStr)){
            throw new GameException(new CODE(9999, "参数不能为空"));
        }
        List<ModeMYCVO> modeMYCVOS = JSONArray.parseArray(mycStr, ModeMYCVO.class);
        for (ModeMYCVO modeMYCVO1 : modeMYCVOS) {
            modeMYCService.setMYC(modeMYCVO1);
        }
        return new WebJsonBean(CODE.SUCCESS);
    }
}
